package com.base.ticket.action;

import static com.base.common.GlobaConstants.ACTION_RESULT_DATA;
import static com.base.common.GlobaConstants.ASYNCHRONOUS;
import static com.base.common.GlobaConstants.CONTENT_TYPE;
import static com.base.common.GlobaConstants.CONTENT_TYPE_JSON;
import static com.base.common.GlobaConstants.JSON;
import static com.base.common.GlobaConstants.ROOT;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.base.common.action.AbstractBaseAction;
import com.base.common.bean.ActionResult;
import com.base.ticket.service.TicketCommonService;
import com.cjy.common.bean.OpAttributes;

/**
 * 程序软件管理
 * 
 * @author Administrator
 * 
 */

@Action("ticketCommonAction")
@Results({ @Result(name = ASYNCHRONOUS, type = JSON, params = { ROOT,
		ACTION_RESULT_DATA, CONTENT_TYPE, CONTENT_TYPE_JSON }) })
public class TicketCommonAction extends AbstractBaseAction {

	private static final long serialVersionUID = 1L;

	@Resource
	private TicketCommonService ticketCommonService;

	private int ticketScore; // 工单评分

	private String code; // 工单号

	private String ticketIds; // 工单id集合，以逗号分隔

	public int getTicketScore() {
		return ticketScore;
	}

	public void setTicketScore(int ticketScore) {
		this.ticketScore = ticketScore;
	}

	public String getTicketIds() {
		return ticketIds;
	}

	public void setTicketIds(String ticketIds) {
		this.ticketIds = ticketIds;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * 评价工单
	 * 
	 * @return
	 */
	public String evaluateTicket() {
		try {
			actionResult = new ActionResult(new OpAttributes().add(
					"code",
					ticketCommonService.evaluateTicket(ticketScore,
							Integer.valueOf((ticketIds.split(","))[0].trim()))));
		} catch (Exception e) {
			e.printStackTrace();
			actionResult = new ActionResult(new OpAttributes().add("code", 0));
		}
		return returnType();
	}

	/**
	 * 删除工单图片，根据工单code
	 * 
	 * @return
	 */
	public String deletePicByCode() {
		try {
			actionResult = new ActionResult(new OpAttributes().add("code",
					ticketCommonService.deletePicByCode(code)));
		} catch (Exception e) {
			e.printStackTrace();
			actionResult = new ActionResult(new OpAttributes().add("code", 0));
		}
		return returnType();
	}

	/**
	 * 根据工单号获取工单id
	 * 
	 * @return
	 */
	public String getIdByCode() {
		try {
			Map id = new HashMap();
			id.put("id", ticketCommonService.queryIdByCode(code));
			actionResult = new ActionResult(new OpAttributes().add("code", 1)
					.add("result", id));
		} catch (Exception e) {
			e.printStackTrace();
			actionResult = new ActionResult(new OpAttributes().add("code", 0));
		}
		return returnType();
	}
}
